package com.pig4cloud.pigx.strategy.runner;

import com.pig4cloud.pigx.strategy.service.StrategyContractService;
import com.pig4cloud.pigx.strategy.service.StrategyGroupContractService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * redis缓存初始化
 */
@Component
@Slf4j
@AllArgsConstructor
public class InitRedisRunner implements ApplicationRunner {

	private final StrategyContractService contractService;

	private final StrategyGroupContractService strategyGroupContractService;

	@Override
	public void run(ApplicationArguments args){
		initStrategyContract();
		initStrategyGroupContract();
	}

	/**
	 * 策略 redis初始化
	 */
	private void initStrategyContract() {
		try {
			contractService.initRedis();
			log.info("策略 redis 初始化完成");
		} catch (Exception e) {
			log.error("策略 redis 初始化失败");
		}
	}

	/**
	 * 策略组-合约 redis初始化
	 */
	private void initStrategyGroupContract() {
		try {
			strategyGroupContractService.initRedis();
			log.info("策略组-合约 redis 初始化完成");
		} catch (Exception e) {
			log.error("策略组-合约 redis 初始化失败");
		}
	}

}
